﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AsterNET.FastAGI.Command;

namespace AsterNET.Extensions.FastAGI.Helpers
{
    public class UserEventHelper
    {
        /// <summary>
        /// Send an arbitrary event to the manager interface
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static ExecCommand UserEvent(string eventName, params KeyValuePair<string, string>[] fields)
        {
            return UserEvent(eventName, string.Join(",",
                fields.Select(x => x.Key + ":" + x.Value)));
        }

        /// <summary>
        /// Send an arbitrary event to the manager interface
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public static ExecCommand UserEvent(string eventName, string body)
        {
            return new ExecCommand("UserEvent", string.Format("{0},{1}", 
                eventName, body));
        }

    }
}
